import { getDepartmentsService, getCompanysService } from '@/api/usercenter';

import {
  SequenceEnums,
  AuthEnums,
  BussinessEnums,
  TransferTypeEnums,
  CompleteEnums,
  CateLevelEnums,
  MetalEnums
} from './enum'

export const SEQUENCE_OPTIONS = SequenceEnums.options // 部门序列下拉集合
export const AUTH_OPTIONS = AuthEnums.options // 授权状态下拉集合
export const CATE_LEVEL_OPTIONS = CateLevelEnums.options // 品类等级下拉集合
export const BUSINESS_OPTIONS = BussinessEnums.options // 业务类型下拉集合
export const COMPLETE_OPTIONS = CompleteEnums.options // 商品负责人完善状态下拉集合
export const METAL_OPTIONS = MetalEnums.options // 是否金属制品下拉集合

export const SEQUENCE_MAPS = SequenceEnums.maps // 部门序列映射关系
export const AUTH_MAPS = AuthEnums.maps // 授权状态映射关系
export const COMPLETE_MAPS = CompleteEnums.maps // 商品负责人完善状态映射关系
export const METAL_ENUMS_MAPS = MetalEnums.maps // 是否金属

export const SEQUENCE_VALUES = SequenceEnums.values // 部门序列枚举值
export const AUTH_VALUES = AuthEnums.values // 授权状态枚举值
export const CATE_LEVEL_VALUES = CateLevelEnums.values // 品类等级枚举值
export const BUSINESS_VALUES = BussinessEnums.values // 业务类型枚举值
export const METAL_VALUES = MetalEnums.values // 是否金属制品枚举值
export const TRANSFER_TYPE_VALUES = TransferTypeEnums.values // 穿梭框类型枚举值
console.log(BUSINESS_OPTIONS);
export const FORM_ITEMS = [
  {
    label: '部门名称',
    prop: 'departmentId',
    type: 'select',
    clearable: true,
    remote: true,
    remoteMethod: getDepartmentsService,
    paramKey: 'departmentName',
    optionKeys: { valueKey: 'departmentNumber', labelKey: 'departmentName', codeKey: 'companyName' }
  },
  {
    label: '部门ID',
    prop: 'departmentId',
    type: 'select',
    remote: true,
    remoteMethod: getDepartmentsService,
    paramKey: 'departmentId',
    optionKeys: { valueKey: 'departmentNumber', labelKey: 'departmentId' }
  },
  {
    label: '公司名称',
    prop: 'hrOrganizeId',
    type: 'select',
    clearable: true,
    remote: true,
    remoteMethod: getCompanysService,
    paramKey: 'companyName',
    optionKeys: { valueKey: 'hrCompanyId', labelKey: 'companyName' }
  },
  {
    label: '部门序列',
    prop: 'sequenceType',
    type: 'select',
    clearable: true,
    options: SequenceEnums.omitOptions(['NoData']),
    clearable: true
  },
  {
    label: '授权状态',
    prop: 'authStatus',
    type: 'select',
    clearable: true,
    options: AUTH_OPTIONS,
    clearable: true
  },
  {
    label: '业务类型',
    prop: 'productDepartmentTypes',
    type: 'select',
    clearable: true,
    options: BUSINESS_OPTIONS,
    clearable: true,
    multiple: true,
    defaultVal: []
  },
  {
    label: '商品负责人完善状态',
    prop: 'dutyPersonStatus',
    type: 'select',
    clearable: true,
    options: COMPLETE_OPTIONS,
    clearable: true
  },
]

export const TABLE_COLUMNS = [
  {
    title: '部门ID',
    key: 'departmentId'
  },
  {
    title: '部门名称',
    key: 'departmentName'
  },
  {
    title: '所属公司',
    key: 'companyName'
  },
  {
    title: '上级部门',
    key: 'parentDepartmentName'
  },
  {
    title: '部门序列',
    render: (h, { row }) => <span>{ SEQUENCE_MAPS[row.departmentSequenceType] ?? '' }</span>
  },
  {
    title: '商品序列业务类型',
    width: 150,
    render: (h, { row }) => <span>{ (row.sequenceDetailList ?? []).join('') }</span>
  },
  {
    title: '授权状态',
    render: (h, { row }) => <span>{ AUTH_MAPS[row.authStatus] ?? '' }</span>
  },
  {
    title: '授权品类',
    key: 'categories'
  },
  {
    title: '商品负责人完善状态',
    width: 150,
    render: (h, { row }) => <span>{
      row.authStatus == AUTH_VALUES.Not ? '' : (COMPLETE_MAPS[row.dutyPersonStatus] ?? '')
    }</span>
  }
]

// 品类穿梭框属性
export const CategoryProps = {
  sourceProps: { label: 'categoryName', key: 'uuid', code: 'categoryNo' },
  leftTitle: '品类列表',
  rightTitle: '已选品类',
}

// 品牌穿梭框属性
export const BrandProps = {
  sourceProps: { label: 'brandName', key: 'uuid' },
  leftTitle: '品牌列表',
  rightTitle: '已选品牌',
}

export const EDIT_AUTH_FORM_ITEMS = [
  { label: '部门名称', prop: 'departmentName' },
  { label: '部门ID', prop: 'departmentId' },
  { label: '所属公司', prop: 'companyName' },
  {
    label: '部门序列',
    prop: 'departmentSequence',
    type: 'select',
    disabled: true,
    options: SEQUENCE_OPTIONS
  },
  {
    label: '业务类型',
    prop: 'productDepartmentTypes',
    type: 'select',
    options: BUSINESS_OPTIONS,
    multiple: true,
    defaultVal: []
  }
]

export const VIEW_PERSON_TABLE_COLUMNS = [
  {
    title: '部门名称',
    key: 'hrDepartmentName'
  },
  {
    title: '员工姓名',
    key: 'userName'
  },
  {
    title: '员工编码',
    key: 'jobNumber'
  },
  {
    title: '品类编码',
    key: 'categoryNo'
  },
  {
    title: '负责品类',
    render: (h, { row }) => <span>{ row.type == TRANSFER_TYPE_VALUES.Category ? row.mappingName : '' }</span>
  },
  {
    title: '负责品牌',
    render: (h, { row }) => <span>{ row.type == TRANSFER_TYPE_VALUES.Brand ? row.mappingName : '' }</span>
  }
]
// 初始化 商品负责人与品类/品牌关系表格表头
export const initRelationTableCulumns = (parent) => {
  return [
    {
      title: '员工',
      key: 'userName'
    },
    {
      title: '品牌/品类',
      key: 'mappingName', width: 150
    },
    {
      title: '是否金属',
      key: 'isMetal',
      render: (h, { row }) => {
        const { isMetal } = row
        return <span>{METAL_ENUMS_MAPS[isMetal]}</span>
      }
    },
    {
      title: '操作',
      render: (h, { row, index }) => {
        const DeleteIcon = parent.DeleteIcon;
        return <DeleteIcon onDelete={ () => { parent.handleDeleteSelected(row, index) }}/>
      }
    }
  ]
}
